﻿using FB.Data.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;

namespace FB.Providers.AEInfo
{
    public enum AEDetailStatus
    {
        Active = 10,
        Terminated = 90,
    }

    public class AEDbContext : DbContextBase
    {

        public DbSet<AEBaseInfo> AEInfos { get; set; }
        public DbSet<AEDetail> AEDetails { get; set; }
        public DbSet<AEMappingHistory> AEMappingHistories { get; set; }

        public DbSet<Location> Locations { get; set; }
        public DbSet<RoomSize> RoomSize { get; set; }
        public DbSet<Branch> Branches { get; set; }
        public DbSet<AllocationHistory> AllocationHistories { get; set; }

        public DbSet<ClientDetail> ClientDetails { get; set; }
        public DbSet<ClientAllocationHistory> ClientAllocationHistories { get; set; }

        public DbSet<BankAccount> BankAccounts { get; set; }
        public DbSet<JoinHistory> JoinHistories { get; set; }

        public DbSet<Holiday> Holidays { get; set; }

        #region table view 

        //Database:fb9070
        public DbSet<ClientBaseInfo> ClientInfo { get; set; }
        
        //Database:HouseKeep 
        public DbSet<SecuritiesCommissionSummary> SecuritiesCommissionSummaries { get; set; }

        #endregion

        public DbSet<QuoteServiceRecord> QuoteServiceRecords { get; set; }

        

        //public AEDbContext() { throw new Exception("Not Implemented"); }
        public AEDbContext() : base() { }
        public AEDbContext(string ConnectionStringName): base(ConnectionStringName)
        {
            Database.SetInitializer<AEDbContext>(null);
            this.Database.Initialize(false);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            modelBuilder.Entity<AEDetail>()
                .HasMany<AEDetail>(m => m.AEGroupUsers)
                //.WithOptional(m => m.AEMaster)
                .WithMany(m => m.AEMasters)
            .Map(map =>
            {
                map.ToTable("BASE_AEGroups", "ae");
                map.MapLeftKey("MasterAEID");
                map.MapRightKey("AEID");
            });

            base.OnModelCreating(modelBuilder);
        }
    }
}
